package com.ym.excel.jfree;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.renderer.category.BarRenderer;

import java.text.DecimalFormat;
import java.util.UUID;

/**
 * @Author: smuswc
 * @Date: 2018/2/7 14:13
 * @Description:
 */
public class YMJFreeBarChart extends YMJFreeLineChart {

    public String drawChart(JFreeChart jFreeChart, String path, Integer width, Integer height) throws Exception {
        // 图片路径
        String fileName = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        path += fileSeparator + fileName + ".png";

        BarRenderer barRenderer = (BarRenderer) jFreeChart.getCategoryPlot().getRenderer();
        // 设置显示数值
        barRenderer.setItemLabelAnchorOffset(5f);
        barRenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat()));
        barRenderer.setDefaultItemLabelsVisible(true);
        drawAxialChart(jFreeChart, path, width, height);
        return path;
    }
}
